package com.tomehay.termprojectmanage_server.controller;


import com.tomehay.termprojectmanage_server.pojo.Model.GroupTask;
import com.tomehay.termprojectmanage_server.pojo.VO.GroupTaskVO;
import com.tomehay.termprojectmanage_server.pojo.VO.ResultVO;
import com.tomehay.termprojectmanage_server.service.GroupTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tomehay
 * @since 2023-06-20
 */
@RestController
@RequestMapping("api/groupTask")
public class GroupTaskController {

    @Autowired
    private GroupTaskService groupTaskService;



    @RequestMapping("/list")
    //@RequiresPermissions("ccm:unit:list")
    /*
    查询参数：
    groupID
    termProjectId
    到时候需要去GroupTaskMapper更改sql语句
     */
    public List<GroupTask> findById(@RequestParam Map<String, Object> params,
                                    @RequestParam(defaultValue = "") Integer groupID,
                                    @RequestParam(defaultValue = "") Integer termProjectId){
        List<GroupTask> page = groupTaskService.queryPage(groupID,termProjectId);
        return page;
    }

    @GetMapping("/FindUnEndedGroupTask")
    public ResultVO<List<GroupTaskVO>> FindUnEndedGroupTask(int course_id){
        return groupTaskService.FindUnEndedGroupTask(course_id);
    }

    @GetMapping("/FindUnEndedGroupTaskByTermProjectId")
    public ResultVO<List<GroupTaskVO>> FindUnEndedGroupTaskByTermProjectId(int term_projectId){
        return groupTaskService.FindUnEndedGroupTaskByTermProjectId(term_projectId);
    }

    @GetMapping("/FindEndedGroupTaskByTermProjectId")
    public ResultVO<List<GroupTaskVO>> FindEndedGroupTaskByTermProjectId(int term_projectId){
        return groupTaskService.FindEndedGroupTaskByTermProjectId(term_projectId);
    }

    @GetMapping("/GetOne")
    public ResultVO<GroupTask> GetOne(int id){
        return groupTaskService.GetOne(id);
    }

    @GetMapping("/FinishGroupTask")
    public ResultVO<Void> FinishGroupTask(int id){
        return groupTaskService.FinishGroupTask(id);
    }

    @DeleteMapping("/DeleteCode")
    public ResultVO<Void> DeleteCode(int id,String path){
        return groupTaskService.DeleteCode(id,path);
    }

    @DeleteMapping("/DeleteDoc")
    public ResultVO<Void> DeleteDoc(int id,String path){
        return groupTaskService.DeleteDoc(id,path);
    }

    @GetMapping("/FindEndedGroupTask")
    public ResultVO<List<GroupTaskVO>> FindEndedGroupTask(int course_id){
        return groupTaskService.FindEndedGroupTask(course_id);
    }

    @PostMapping("/UpLoadCode")
    public ResultVO<Void> UpLoadCode(@RequestParam(value = "file")MultipartFile multipartFile,
                                     @RequestParam(value = "id") int id) throws IOException {
        return groupTaskService.UpLoadCode(multipartFile,id);
    }

    @PostMapping("/UpLoadDoc")
    public ResultVO<Void> UpLoadDoc(@RequestParam(value = "file")MultipartFile multipartFile,
                                     @RequestParam(value = "id") int id) throws IOException {
        return groupTaskService.UpLoadDoc(multipartFile,id);
    }

    @RequestMapping("/Export")
    public void exportExcelModel(@RequestParam String path ,HttpServletResponse response) throws Exception {
        groupTaskService.exportFile(path,response);
    }

    @PostMapping("/CreateTask")
    public ResultVO<Void> CreateTask(@RequestBody GroupTask groupTask){
        return groupTaskService.CreateTask(groupTask);
    }

    @GetMapping("/RejectTask")
    public ResultVO<Void> RejectTask(int id){
        return groupTaskService.RejectTask(id);
    }

    @GetMapping("/EndGroupTask")
    public ResultVO<Void> EndGroupTask(int id){
        return groupTaskService.EndGroupTask(id);
    }
}
